<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生社交媒体成瘾分析报告</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        :root {
            --primary-color: #4a90e2;
            --secondary-color: #f5f6fa;
            --text-color: #2c3e50;
            --border-color: #e0e6ed;
        }
        
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: var(--secondary-color);
            color: var(--text-color);
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            text-align: center;
            padding: 30px 0;
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 30px;
        }
        
        .header h1 {
            color: var(--primary-color);
            margin: 0;
        }
        
        .header p {
            color: #666;
            margin: 10px 0 0;
        }
        
        .section {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .section h2 {
            color: var(--primary-color);
            margin-top: 0;
            padding-bottom: 10px;
            border-bottom: 2px solid var(--border-color);
        }
        
        .chart-container {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 20px;
            margin-top: 20px;
        }
        
        .chart {
            height: 400px;
            border-radius: 10px;
            padding: 15px;
            background: white;
        }
        
        .full-width {
            grid-column: 1 / -1;
        }
        
        @media (max-width: 768px) {
            .chart-container {
                grid-template-columns: 1fr;
            }
        }
        
        .loading {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.9);
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 24px;
            z-index: 1000;
        }

        .summary {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            margin: 10px 0;
        }

        .summary h3 {
            color: var(--primary-color);
            margin-top: 0;
        }

        .key-findings {
            margin: 20px 0;
            padding: 15px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .key-findings ul {
            margin: 10px 0;
            padding-left: 20px;
        }

        .key-findings li {
            margin: 8px 0;
            line-height: 1.5;
        }
    </style>
</head>
<body>
    <div class="loading">正在加载数据...</div>
    <div class="container">
        <div class="header">
            <h1>学生社交媒体成瘾分析报告</h1>
            <p>基于跨国调查数据的综合分析</p>
        </div>

        <div class="section">
            <h2>研究概述</h2>
            <div class="summary">
                <p>本研究基于对16-25岁学生的社交媒体使用行为调查，涵盖多个国家和地区的学生群体。研究重点关注社交媒体使用对学生学习、心理健康和社交关系的影响。</p>
            </div>
            <div class="key-findings">
                <h3>主要发现</h3>
                <div id="keyFindings">
                    <!-- 将通过JavaScript动态填充 -->
                </div>
            </div>
        </div>

        <!-- 基本人口统计 -->
        <div class="section">
            <h2>人口统计分析</h2>
            <div class="chart-container">
                <div id="ageChart" class="chart"></div>
                <div id="genderChart" class="chart"></div>
                <div id="academicChart" class="chart"></div>
                <div id="countryChart" class="chart"></div>
            </div>
        </div>

        <!-- 使用情况分析 -->
        <div class="section">
            <h2>社交媒体使用情况</h2>
            <div class="chart-container">
                <div id="platformChart" class="chart"></div>
                <div id="usageDistChart" class="chart"></div>
                <div id="academicImpactChart" class="chart"></div>
                <div id="addictionLevelsChart" class="chart"></div>
            </div>
        </div>

        <!-- 健康影响分析 -->
        <div class="section">
            <h2>健康与生活质量影响</h2>
            <div class="chart-container">
                <div id="sleepChart" class="chart"></div>
                <div id="mentalHealthChart" class="chart"></div>
                <div id="usageVsHealthChart" class="chart full-width"></div>
            </div>
        </div>

        <!-- 关系影响分析 -->
        <div class="section">
            <h2>社交关系分析</h2>
            <div class="chart-container">
                <div id="relationshipChart" class="chart"></div>
                <div id="conflictsChart" class="chart"></div>
            </div>
        </div>

        <!-- 平台特定分析 -->
        <div class="section">
            <h2>平台对比分析</h2>
            <div class="chart-container">
                <div id="platformAddictionChart" class="chart"></div>
                <div id="platformMentalHealthChart" class="chart"></div>
            </div>
        </div>
    </div>

    <script>
        // 内置数据
        const rawData = [
            {"Student_ID":"1","Age":"19","Gender":"Female","Academic_Level":"Undergraduate","Country":"Bangladesh","Avg_Daily_Usage_Hours":"5.2","Most_Used_Platform":"Instagram","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"6.5","Mental_Health_Score":"6","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"3","Addicted_Score":"8"},
            {"Student_ID":"2","Age":"22","Gender":"Male","Academic_Level":"Graduate","Country":"India","Avg_Daily_Usage_Hours":"2.1","Most_Used_Platform":"Twitter","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"7.5","Mental_Health_Score":"8","Relationship_Status":"Single","Conflicts_Over_Social_Media":"0","Addicted_Score":"3"},
            {"Student_ID":"3","Age":"20","Gender":"Female","Academic_Level":"Undergraduate","Country":"USA","Avg_Daily_Usage_Hours":"6.0","Most_Used_Platform":"TikTok","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"5.0","Mental_Health_Score":"5","Relationship_Status":"Complicated","Conflicts_Over_Social_Media":"4","Addicted_Score":"9"},
            {"Student_ID":"4","Age":"18","Gender":"Male","Academic_Level":"High School","Country":"UK","Avg_Daily_Usage_Hours":"3.0","Most_Used_Platform":"YouTube","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"7.0","Mental_Health_Score":"7","Relationship_Status":"Single","Conflicts_Over_Social_Media":"1","Addicted_Score":"4"},
            {"Student_ID":"5","Age":"21","Gender":"Male","Academic_Level":"Graduate","Country":"Canada","Avg_Daily_Usage_Hours":"4.5","Most_Used_Platform":"Facebook","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"6.0","Mental_Health_Score":"6","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"2","Addicted_Score":"7"},
            {"Student_ID":"6","Age":"19","Gender":"Female","Academic_Level":"Undergraduate","Country":"Australia","Avg_Daily_Usage_Hours":"7.2","Most_Used_Platform":"Instagram","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"4.5","Mental_Health_Score":"4","Relationship_Status":"Complicated","Conflicts_Over_Social_Media":"5","Addicted_Score":"9"},
            {"Student_ID":"7","Age":"23","Gender":"Male","Academic_Level":"Graduate","Country":"Germany","Avg_Daily_Usage_Hours":"1.5","Most_Used_Platform":"LinkedIn","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"8.0","Mental_Health_Score":"9","Relationship_Status":"Single","Conflicts_Over_Social_Media":"0","Addicted_Score":"2"},
            {"Student_ID":"8","Age":"20","Gender":"Female","Academic_Level":"Undergraduate","Country":"Brazil","Avg_Daily_Usage_Hours":"5.8","Most_Used_Platform":"Snapchat","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"6.0","Mental_Health_Score":"6","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"2","Addicted_Score":"8"},
            {"Student_ID":"9","Age":"18","Gender":"Male","Academic_Level":"High School","Country":"Japan","Avg_Daily_Usage_Hours":"4.0","Most_Used_Platform":"TikTok","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"6.5","Mental_Health_Score":"7","Relationship_Status":"Single","Conflicts_Over_Social_Media":"1","Addicted_Score":"5"},
            {"Student_ID":"10","Age":"21","Gender":"Female","Academic_Level":"Graduate","Country":"South Korea","Avg_Daily_Usage_Hours":"3.3","Most_Used_Platform":"Instagram","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"7.0","Mental_Health_Score":"7","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"1","Addicted_Score":"4"},
            {"Student_ID":"11","Age":"19","Gender":"Male","Academic_Level":"Undergraduate","Country":"France","Avg_Daily_Usage_Hours":"4.8","Most_Used_Platform":"Snapchat","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"6.2","Mental_Health_Score":"5","Relationship_Status":"Complicated","Conflicts_Over_Social_Media":"3","Addicted_Score":"7"},
            {"Student_ID":"12","Age":"20","Gender":"Female","Academic_Level":"Undergraduate","Country":"Spain","Avg_Daily_Usage_Hours":"5.5","Most_Used_Platform":"TikTok","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"5.8","Mental_Health_Score":"6","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"2","Addicted_Score":"8"},
            {"Student_ID":"13","Age":"22","Gender":"Male","Academic_Level":"Graduate","Country":"Italy","Avg_Daily_Usage_Hours":"2.8","Most_Used_Platform":"LinkedIn","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"7.2","Mental_Health_Score":"8","Relationship_Status":"Single","Conflicts_Over_Social_Media":"1","Addicted_Score":"4"},
            {"Student_ID":"14","Age":"18","Gender":"Female","Academic_Level":"High School","Country":"Mexico","Avg_Daily_Usage_Hours":"6.5","Most_Used_Platform":"Instagram","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"5.5","Mental_Health_Score":"5","Relationship_Status":"Single","Conflicts_Over_Social_Media":"4","Addicted_Score":"9"},
            {"Student_ID":"15","Age":"21","Gender":"Male","Academic_Level":"Undergraduate","Country":"Russia","Avg_Daily_Usage_Hours":"3.7","Most_Used_Platform":"YouTube","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"6.8","Mental_Health_Score":"7","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"2","Addicted_Score":"5"},
            {"Student_ID":"16","Age":"20","Gender":"Female","Academic_Level":"Undergraduate","Country":"China","Avg_Daily_Usage_Hours":"4.2","Most_Used_Platform":"TikTok","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"6.0","Mental_Health_Score":"6","Relationship_Status":"Complicated","Conflicts_Over_Social_Media":"3","Addicted_Score":"7"},
            {"Student_ID":"17","Age":"24","Gender":"Male","Academic_Level":"Graduate","Country":"Sweden","Avg_Daily_Usage_Hours":"2.0","Most_Used_Platform":"LinkedIn","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"7.8","Mental_Health_Score":"8","Relationship_Status":"Single","Conflicts_Over_Social_Media":"0","Addicted_Score":"3"},
            {"Student_ID":"18","Age":"19","Gender":"Female","Academic_Level":"High School","Country":"Norway","Avg_Daily_Usage_Hours":"5.0","Most_Used_Platform":"Instagram","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"5.7","Mental_Health_Score":"5","Relationship_Status":"In Relationship","Conflicts_Over_Social_Media":"3","Addicted_Score":"8"},
            {"Student_ID":"19","Age":"21","Gender":"Male","Academic_Level":"Undergraduate","Country":"Denmark","Avg_Daily_Usage_Hours":"3.5","Most_Used_Platform":"Facebook","Affects_Academic_Performance":"No","Sleep_Hours_Per_Night":"6.7","Mental_Health_Score":"7","Relationship_Status":"Single","Conflicts_Over_Social_Media":"1","Addicted_Score":"5"},
            {"Student_ID":"20","Age":"20","Gender":"Female","Academic_Level":"Undergraduate","Country":"Netherlands","Avg_Daily_Usage_Hours":"4.7","Most_Used_Platform":"Snapchat","Affects_Academic_Performance":"Yes","Sleep_Hours_Per_Night":"5.9","Mental_Health_Score":"6","Relationship_Status":"Complicated","Conflicts_Over_Social_Media":"3","Addicted_Score":"7"}
        ];

        // 初始化所有图表
        const charts = {
            ageChart: echarts.init(document.getElementById('ageChart')),
            genderChart: echarts.init(document.getElementById('genderChart')),
            academicChart: echarts.init(document.getElementById('academicChart')),
            countryChart: echarts.init(document.getElementById('countryChart')),
            platformChart: echarts.init(document.getElementById('platformChart')),
            usageDistChart: echarts.init(document.getElementById('usageDistChart')),
            academicImpactChart: echarts.init(document.getElementById('academicImpactChart')),
            addictionLevelsChart: echarts.init(document.getElementById('addictionLevelsChart')),
            sleepChart: echarts.init(document.getElementById('sleepChart')),
            mentalHealthChart: echarts.init(document.getElementById('mentalHealthChart')),
            usageVsHealthChart: echarts.init(document.getElementById('usageVsHealthChart')),
            relationshipChart: echarts.init(document.getElementById('relationshipChart')),
            conflictsChart: echarts.init(document.getElementById('conflictsChart')),
            platformAddictionChart: echarts.init(document.getElementById('platformAddictionChart')),
            platformMentalHealthChart: echarts.init(document.getElementById('platformMentalHealthChart'))
        };

        // 数据处理函数
        function processData(data) {
            // 数据统计对象
            const stats = {
                age: {},
                gender: {},
                academic: {},
                country: {},
                platform: {},
                usage: {},
                academic_impact: {},
                sleep: {},
                mental_health: {},
                relationship: {},
                addiction: {},
                platform_addiction: {},
                platform_mental_health: {},
                usage_vs_health: {},
                usage_vs_sleep: {},
                addiction_vs_conflicts: {}
            };

            // 处理每一行数据
            data.forEach(row => {
                // 年龄统计
                stats.age[row.Age] = (stats.age[row.Age] || 0) + 1;
                
                // 性别统计
                stats.gender[row.Gender] = (stats.gender[row.Gender] || 0) + 1;
                
                // 学历统计
                stats.academic[row.Academic_Level] = (stats.academic[row.Academic_Level] || 0) + 1;
                
                // 国家统计
                stats.country[row.Country] = (stats.country[row.Country] || 0) + 1;
                
                // 平台统计
                stats.platform[row.Most_Used_Platform] = (stats.platform[row.Most_Used_Platform] || 0) + 1;
                
                // 使用时长统计
                const usage = Math.round(parseFloat(row.Avg_Daily_Usage_Hours));
                stats.usage[usage] = (stats.usage[usage] || 0) + 1;
                
                // 学业影响统计
                stats.academic_impact[row.Affects_Academic_Performance] = 
                    (stats.academic_impact[row.Affects_Academic_Performance] || 0) + 1;
                
                // 睡眠时间统计
                const sleep = Math.round(parseFloat(row.Sleep_Hours_Per_Night));
                stats.sleep[sleep] = (stats.sleep[sleep] || 0) + 1;
                
                // 心理健康统计
                stats.mental_health[row.Mental_Health_Score] = 
                    (stats.mental_health[row.Mental_Health_Score] || 0) + 1;
                
                // 关系状态统计
                stats.relationship[row.Relationship_Status] = 
                    (stats.relationship[row.Relationship_Status] || 0) + 1;
                
                // 成瘾程度统计
                stats.addiction[row.Addicted_Score] = 
                    (stats.addiction[row.Addicted_Score] || 0) + 1;

                // 平台成瘾关系
                if (!stats.platform_addiction[row.Most_Used_Platform]) {
                    stats.platform_addiction[row.Most_Used_Platform] = {
                        sum: 0,
                        count: 0
                    };
                }
                stats.platform_addiction[row.Most_Used_Platform].sum += parseInt(row.Addicted_Score);
                stats.platform_addiction[row.Most_Used_Platform].count += 1;

                // 平台心理健康关系
                if (!stats.platform_mental_health[row.Most_Used_Platform]) {
                    stats.platform_mental_health[row.Most_Used_Platform] = {
                        sum: 0,
                        count: 0
                    };
                }
                stats.platform_mental_health[row.Most_Used_Platform].sum += parseInt(row.Mental_Health_Score);
                stats.platform_mental_health[row.Most_Used_Platform].count += 1;

                // 使用时长与健康关系
                const usageKey = Math.round(parseFloat(row.Avg_Daily_Usage_Hours));
                if (!stats.usage_vs_health[usageKey]) {
                    stats.usage_vs_health[usageKey] = {
                        sum: 0,
                        count: 0
                    };
                }
                stats.usage_vs_health[usageKey].sum += parseInt(row.Mental_Health_Score);
                stats.usage_vs_health[usageKey].count += 1;

                // 使用时长与睡眠关系
                if (!stats.usage_vs_sleep[usageKey]) {
                    stats.usage_vs_sleep[usageKey] = {
                        sum: 0,
                        count: 0
                    };
                }
                stats.usage_vs_sleep[usageKey].sum += parseFloat(row.Sleep_Hours_Per_Night);
                stats.usage_vs_sleep[usageKey].count += 1;

                // 成瘾程度与冲突关系
                const addictionKey = row.Addicted_Score;
                if (!stats.addiction_vs_conflicts[addictionKey]) {
                    stats.addiction_vs_conflicts[addictionKey] = {
                        sum: 0,
                        count: 0
                    };
                }
                stats.addiction_vs_conflicts[addictionKey].sum += parseInt(row.Conflicts_Over_Social_Media);
                stats.addiction_vs_conflicts[addictionKey].count += 1;
            });

            // 计算平均值
            for (let platform in stats.platform_addiction) {
                stats.platform_addiction[platform] = 
                    stats.platform_addiction[platform].sum / stats.platform_addiction[platform].count;
            }
            for (let platform in stats.platform_mental_health) {
                stats.platform_mental_health[platform] = 
                    stats.platform_mental_health[platform].sum / stats.platform_mental_health[platform].count;
            }
            for (let usage in stats.usage_vs_health) {
                stats.usage_vs_health[usage] = 
                    stats.usage_vs_health[usage].sum / stats.usage_vs_health[usage].count;
            }
            for (let usage in stats.usage_vs_sleep) {
                stats.usage_vs_sleep[usage] = 
                    stats.usage_vs_sleep[usage].sum / stats.usage_vs_sleep[usage].count;
            }
            for (let addiction in stats.addiction_vs_conflicts) {
                stats.addiction_vs_conflicts[addiction] = 
                    stats.addiction_vs_conflicts[addiction].sum / stats.addiction_vs_conflicts[addiction].count;
            }

            return stats;
        }

        // 更新主要发现
        function updateKeyFindings(stats) {
            const avgUsage = Object.entries(stats.usage).reduce((acc, [hours, count]) => 
                acc + (parseFloat(hours) * count), 0) / 
                Object.values(stats.usage).reduce((a, b) => a + b, 0);
            
            const avgMentalHealth = Object.entries(stats.mental_health).reduce((acc, [score, count]) => 
                acc + (parseFloat(score) * count), 0) / 
                Object.values(stats.mental_health).reduce((a, b) => a + b, 0);
            
            const avgSleep = Object.entries(stats.sleep).reduce((acc, [hours, count]) => 
                acc + (parseFloat(hours) * count), 0) / 
                Object.values(stats.sleep).reduce((a, b) => a + b, 0);

            const findings = `
                <ul>
                    <li>平均每日社交媒体使用时长：${avgUsage.toFixed(1)}小时</li>
                    <li>平均心理健康评分：${avgMentalHealth.toFixed(1)}/10</li>
                    <li>平均睡眠时间：${avgSleep.toFixed(1)}小时</li>
                    <li>学业影响：${(stats.academic_impact['是'] / 
                        (stats.academic_impact['是'] + stats.academic_impact['否']) * 100).toFixed(1)}%的学生报告社交媒体对学习有负面影响</li>
                </ul>
            `;
            document.getElementById('keyFindings').innerHTML = findings;
        }

        // 直接处理数据
        const stats = processData(rawData);
        updateKeyFindings(stats);

        // 年龄分布
        charts.ageChart.setOption({
            title: { text: '年龄分布' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.age).sort((a, b) => a - b),
                name: '年龄'
            },
            yAxis: { type: 'value', name: '人数' },
            series: [{
                data: Object.keys(stats.age).sort((a, b) => a - b)
                    .map(key => stats.age[key]),
                type: 'bar',
                color: '#4a90e2'
            }]
        });

        // 性别分布
        charts.genderChart.setOption({
            title: { text: '性别分布' },
            tooltip: { trigger: 'item' },
            legend: { orient: 'vertical', left: 'left' },
            series: [{
                type: 'pie',
                radius: '60%',
                data: Object.entries(stats.gender).map(([name, value]) => ({
                    name, value
                })),
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }]
        });

        // 学历分布
        charts.academicChart.setOption({
            title: { text: '学历分布' },
            tooltip: { trigger: 'item' },
            legend: { orient: 'vertical', left: 'left' },
            series: [{
                type: 'pie',
                radius: ['40%', '70%'],
                data: Object.entries(stats.academic).map(([name, value]) => ({
                    name, value
                }))
            }]
        });

        // 国家分布
        charts.countryChart.setOption({
            title: { text: '国家分布' },
            tooltip: {},
            xAxis: {
                type: 'value',
                name: '人数'
            },
            yAxis: {
                type: 'category',
                data: Object.keys(stats.country),
                axisLabel: { interval: 0 }
            },
            series: [{
                data: Object.values(stats.country),
                type: 'bar',
                color: '#91cc75'
            }]
        });

        // 平台使用情况
        charts.platformChart.setOption({
            title: { text: '最常用社交平台' },
            tooltip: { trigger: 'item' },
            legend: { orient: 'vertical', left: 'left' },
            series: [{
                type: 'pie',
                radius: '60%',
                data: Object.entries(stats.platform).map(([name, value]) => ({
                    name, value
                }))
            }]
        });

        // 使用时长分布
        charts.usageDistChart.setOption({
            title: { text: '每日使用时长分布' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.usage).sort((a, b) => a - b),
                name: '小时'
            },
            yAxis: { type: 'value', name: '人数' },
            series: [{
                data: Object.keys(stats.usage).sort((a, b) => a - b)
                    .map(key => stats.usage[key]),
                type: 'bar',
                color: '#5470c6'
            }]
        });

        // 学业影响
        charts.academicImpactChart.setOption({
            title: { text: '对学业的影响' },
            tooltip: { trigger: 'item' },
            legend: { orient: 'vertical', left: 'left' },
            series: [{
                type: 'pie',
                radius: '60%',
                data: Object.entries(stats.academic_impact).map(([name, value]) => ({
                    name, value
                }))
            }]
        });

        // 成瘾程度分布
        charts.addictionLevelsChart.setOption({
            title: { text: '成瘾程度分布' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.addiction).sort((a, b) => a - b),
                name: '成瘾程度'
            },
            yAxis: { type: 'value', name: '人数' },
            series: [{
                data: Object.keys(stats.addiction).sort((a, b) => a - b)
                    .map(key => stats.addiction[key]),
                type: 'bar',
                color: '#ee6666'
            }]
        });

        // 睡眠时间分布
        charts.sleepChart.setOption({
            title: { text: '平均睡眠时间分布' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.sleep).sort((a, b) => a - b),
                name: '小时'
            },
            yAxis: { type: 'value', name: '人数' },
            series: [{
                data: Object.keys(stats.sleep).sort((a, b) => a - b)
                    .map(key => stats.sleep[key]),
                type: 'bar',
                color: '#73c0de'
            }]
        });

        // 心理健康分布
        charts.mentalHealthChart.setOption({
            title: { text: '心理健康评分分布' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.mental_health).sort((a, b) => a - b),
                name: '评分'
            },
            yAxis: { type: 'value', name: '人数' },
            series: [{
                data: Object.keys(stats.mental_health).sort((a, b) => a - b)
                    .map(key => stats.mental_health[key]),
                type: 'bar',
                color: '#3ba272'
            }]
        });

        // 使用时长vs健康关系
        charts.usageVsHealthChart.setOption({
            title: { text: '使用时长与健康指标的关系' },
            tooltip: { trigger: 'axis' },
            legend: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.usage_vs_health).sort((a, b) => a - b),
                name: '每日使用时长'
            },
            yAxis: [
                { type: 'value', name: '评分', min: 0, max: 10 },
                { type: 'value', name: '小时', min: 0, max: 12 }
            ],
            series: [{
                name: '心理健康评分',
                type: 'line',
                data: Object.keys(stats.usage_vs_health).sort((a, b) => a - b)
                    .map(key => stats.usage_vs_health[key])
            }, {
                name: '睡眠时间',
                type: 'line',
                yAxisIndex: 1,
                data: Object.keys(stats.usage_vs_sleep).sort((a, b) => a - b)
                    .map(key => stats.usage_vs_sleep[key])
            }]
        });

        // 关系状态分布
        charts.relationshipChart.setOption({
            title: { text: '关系状态分布' },
            tooltip: { trigger: 'item' },
            legend: { orient: 'vertical', left: 'left' },
            series: [{
                type: 'pie',
                radius: '60%',
                data: Object.entries(stats.relationship).map(([name, value]) => ({
                    name, value
                }))
            }]
        });

        // 成瘾程度与冲突关系
        charts.conflictsChart.setOption({
            title: { text: '成瘾程度与社交冲突' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.addiction_vs_conflicts).sort((a, b) => a - b),
                name: '成瘾程度'
            },
            yAxis: { type: 'value', name: '平均冲突次数' },
            series: [{
                data: Object.keys(stats.addiction_vs_conflicts).sort((a, b) => a - b)
                    .map(key => stats.addiction_vs_conflicts[key]),
                type: 'line',
                smooth: true
            }]
        });

        // 平台与成瘾关系
        charts.platformAddictionChart.setOption({
            title: { text: '不同平台的平均成瘾程度' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.platform_addiction),
                axisLabel: { interval: 0, rotate: 45 }
            },
            yAxis: { type: 'value', name: '平均成瘾程度' },
            series: [{
                data: Object.values(stats.platform_addiction),
                type: 'bar',
                color: '#fc8452'
            }]
        });

        // 平台与心理健康
        charts.platformMentalHealthChart.setOption({
            title: { text: '不同平台用户的心理健康评分' },
            tooltip: {},
            xAxis: {
                type: 'category',
                data: Object.keys(stats.platform_mental_health),
                axisLabel: { interval: 0, rotate: 45 }
            },
            yAxis: { type: 'value', name: '平均心理健康评分' },
            series: [{
                data: Object.values(stats.platform_mental_health),
                type: 'bar',
                color: '#9a60b4'
            }]
        });

        // 隐藏加载提示
        document.querySelector('.loading').style.display = 'none';

        // 响应式调整
        window.addEventListener('resize', function() {
            Object.values(charts).forEach(chart => chart.resize());
        });
    </script>
</body>
</html> 